package cn.liuhuan1.mongoDb.controller;

import cn.liuhuan1.mongoDb.fastImp.FastDfsImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @Auther: liuhuan
 * @Date: 2021/4/7 - 04 - 07 - 20:33
 * @Description:
 * @version: 1.0
 */
@Controller
@RequestMapping("/fastDfs")
public class FastDfsController {

    @Autowired
    private FastDfsImp fastDfsImp;

    @RequestMapping("/uploadFast")
    @ResponseBody
    public String uploadFast(@RequestBody MultipartFile multipartFile){
      return fastDfsImp.uploadFast(multipartFile);
    }


    @RequestMapping("/upload")
    @ResponseBody
    public String upload(@RequestParam("bytes") byte[] bytes,
                         @RequestParam("fileName") String fileName){
        return fastDfsImp.upload(bytes,fileName);
    }


    @RequestMapping("/uploadFile")
    @ResponseBody
    public String uploadFile(@RequestBody File file){
        return fastDfsImp.uploadFile(file);
    }

    @RequestMapping("/delFileUrl")
    @ResponseBody
    public Integer delFileUrl(@RequestParam("group") String group,
                              @RequestParam("url") String url){
        return fastDfsImp.delFileUrl(group,url);
    }
}
